import fetcher from "./Fetcher";
import {NumberIdAndName} from "../types/BasicModels";
import {GoodsItem} from "../components/GoodsWithSubGoodsSelector";


export function getMarketSettlementPlan(marketId:number){
    return fetcher.get<ConfigureMarketSettlementPlanResponse>(`markets/${marketId}/settlementPlans`)
}

export interface ConfigureMarketSettlementPlanResponse {
    rules: ConfigureMarketSettlementPlanRuleResponse[];
}

export interface ConfigureMarketSettlementPlanRuleResponse {
    id: number;
    name: string;
    note?: string;
    commissionPercentage?: number;
    fixed?: number;
    includedBrands:Array<NumberIdAndName>
    includedCategories:Array<NumberIdAndName>
    includedBrandTags:Array<NumberIdAndName>
    includedGoodsList:Array<GoodsItem>
}


export interface ConfigureMarketSettlementPlanRequest {
    rules: ConfigureMarketSettlementPlanRuleRequest[];
}

export interface ConfigureMarketSettlementPlanRuleRequest {
    name: string;
    note?: string;
    commissionPercentage?: number;
    fixed?: number;
    includedBrandIds: number[];
    includedCategoryIds:number[]
    includedBrandTagIds:Array<number>
    includedGoodsIds:Array<number>
}

export function configureMarketSettlementPlan(marketId:number,request:ConfigureMarketSettlementPlanRequest){
    return fetcher.post<ConfigureMarketSettlementPlanResponse>(`markets/${marketId}/settlementPlans`,{},request)
}

export function reconfigureMarketSettlementPlan(marketId:number,request:ConfigureMarketSettlementPlanRequest){
    return fetcher.put<ConfigureMarketSettlementPlanResponse>(`markets/${marketId}/settlementPlans`,{},request)
}

